package com.chunxuan.langquan.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chunxuan.langquan.R;
import com.chunxuan.langquan.base.Base2Activity;
import com.chunxuan.langquan.base.BaseResult2;
import com.chunxuan.langquan.base.Global;
import com.chunxuan.langquan.dao.bean.CourseDetail;
import com.chunxuan.langquan.dao.http.APIRetrofit;
import com.chunxuan.langquan.support.util.Logg;
import com.chunxuan.langquan.ui.adapter.AllRecordAdapter;
import com.chunxuan.langquan.ui.adapter.CourseRecordAdapter;
import com.ruitu.arad.api.RxUtil;
import com.ruitu.arad.util.ToastUtils;

import java.util.List;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class AllRecordActivity extends Base2Activity {
    private ImageView ivBack;
    private RecyclerView rvAllRecord;
    @Override
    protected int getLayoutRes() {
        return R.layout.activity_all_course_record;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ivBack=findViewById(R.id.iv_back);
        rvAllRecord=findViewById(R.id.rv_all_course_record);
        LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        rvAllRecord.setLayoutManager(layoutManager);
        getCourseRecord();
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    private Disposable getCourseRecord() {
        return APIRetrofit.getDefault().getCourseRecord(Global.HEADER,"")
                .compose(RxUtil.<BaseResult2<List<CourseDetail.CourseInfo>>>subIoObMain())
                .subscribe(new Consumer<BaseResult2<List<CourseDetail.CourseInfo>>>() {
                    @Override
                    public void accept(BaseResult2<List<CourseDetail.CourseInfo>> result2) throws Exception {
                        hideProgress();
                        if (result2.isSuccess()) {
//                            Logg.e("==课程记录-全部=="+result2.getData().get(0).getKecheng_image());
                            AllRecordAdapter allRecordAdapter=new AllRecordAdapter(AllRecordActivity.this,result2.getData());
                            rvAllRecord.setAdapter(allRecordAdapter);
                        } else {
                            ToastUtils.showShort(result2.getMsg());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        hideProgress();
                        throwable.printStackTrace();
//                        ToastUtils.showShort("获取课程记录失败");
                    }
                });
    }
}
